using System;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.UI.WebControls;
using System.Data;
using System.Collections.Generic;


namespace AdminWebSite
{
	public partial class Admin_Baby : AdminBasePage
	{
	
	// Coded by wenbin 2012-9-25 0:00:05
		#region 实体类
		/// <summary>
		/// 实体类
		/// </summary>
		private class Baby
		{
			private int _id = 0;	
			public  int  Id  
			{
				get{ return  _id; }
				set{ _id = value; }
			}
			private string _babyName = string.Empty;	
			public  string  BabyName  
			{
				get{ return  _babyName; }
				set{ _babyName = value; }
			}
			private DateTime _babyBirthday = DateTime.Now;	
			public  DateTime  BabyBirthday  
			{
				get{ return  _babyBirthday; }
				set{ _babyBirthday = value; }
			}
			private int _babySex = 0;	
			public  int  BabySex  
			{
				get{ return  _babySex; }
				set{ _babySex = value; }
			}
			private int _weight = 0;	
			public  int  Weight  
			{
				get{ return  _weight; }
				set{ _weight = value; }
			}
			private int _height = 0;	
			public  int  Height  
			{
				get{ return  _height; }
				set{ _height = value; }
			}
			private string _introduction = string.Empty;	
			public  string  Introduction  
			{
				get{ return  _introduction; }
				set{ _introduction = value; }
			}
			private string _milkBrand = string.Empty;	
			public  string  MilkBrand  
			{
				get{ return  _milkBrand; }
				set{ _milkBrand = value; }
			}
			private string _babyHeadImg = string.Empty;	
			public  string  BabyHeadImg  
			{
				get{ return  _babyHeadImg; }
				set{ _babyHeadImg = value; }
			}
			private string _parentFirstName = string.Empty;	
			public  string  ParentFirstName  
			{
				get{ return  _parentFirstName; }
				set{ _parentFirstName = value; }
			}
			private string _parentLastName = string.Empty;	
			public  string  ParentLastName  
			{
				get{ return  _parentLastName; }
				set{ _parentLastName = value; }
			}
			private int _parentType = 0;	
			public  int  ParentType  
			{
				get{ return  _parentType; }
				set{ _parentType = value; }
			}
			private string _liveProvince = string.Empty;	
			public  string  LiveProvince  
			{
				get{ return  _liveProvince; }
				set{ _liveProvince = value; }
			}
			private string _liveCity = string.Empty;	
			public  string  LiveCity  
			{
				get{ return  _liveCity; }
				set{ _liveCity = value; }
			}
			private string _liveArea = string.Empty;	
			public  string  LiveArea  
			{
				get{ return  _liveArea; }
				set{ _liveArea = value; }
			}
			private string _liveRoad = string.Empty;	
			public  string  LiveRoad  
			{
				get{ return  _liveRoad; }
				set{ _liveRoad = value; }
			}
			private string _zipCode = string.Empty;	
			public  string  ZipCode  
			{
				get{ return  _zipCode; }
				set{ _zipCode = value; }
			}
			private string _eMail = string.Empty;	
			public  string  EMail  
			{
				get{ return  _eMail; }
				set{ _eMail = value; }
			}
			private string _babyTeamName = string.Empty;	
			public  string  BabyTeamName  
			{
				get{ return  _babyTeamName; }
				set{ _babyTeamName = value; }
			}
			private string _babyTeamImg = string.Empty;	
			public  string  BabyTeamImg  
			{
				get{ return  _babyTeamImg; }
				set{ _babyTeamImg = value; }
			}
			private string _babyTeamDeclaration = string.Empty;	
			public  string  BabyTeamDeclaration  
			{
				get{ return  _babyTeamDeclaration; }
				set{ _babyTeamDeclaration = value; }
			}
			private int _confirmTeamId = 0;	
			public  int  ConfirmTeamId  
			{
				get{ return  _confirmTeamId; }
				set{ _confirmTeamId = value; }
			}
			private string _confirmTeamName = string.Empty;	
			public  string  ConfirmTeamName  
			{
				get{ return  _confirmTeamName; }
				set{ _confirmTeamName = value; }
			}
			private int _status = 0;	
			public  int  Status  
			{
				get{ return  _status; }
				set{ _status = value; }
			}
			private DateTime _createTime = DateTime.Now;	
			public  DateTime  CreateTime  
			{
				get{ return  _createTime; }
				set{ _createTime = value; }
			}
			private string _ip = string.Empty;	
			public  string  Ip  
			{
				get{ return  _ip; }
				set{ _ip = value; }
			}
	
	}
		#endregion
	
		dbHelper db = new dbHelper();
		
		/// <summary>
        /// 查询id
        /// </summary>
        public long QId
        {
            get
            {
                return Convert.ToInt64(Request.QueryString["id"]);
            }
        }
		
		protected override void OnInit(EventArgs e)
		{
			base.OnInit(e);
			dbHelper.CheckIsLogin();
		}
	
	
		protected void Page_Load(object sender, EventArgs e)
		{
			string redirectUrl = HttpContext.Current.Request.Url.ToString().Split('?')[0];
			int page = Convert.ToInt32(Request.QueryString["page"]);
			if (page == 0)
				page = 1;
			string urlPage = "page=" + page;
			string strWhere = " 1=1 ";
			string urlParams = "";
			string searchId= dbHelper.FilterSql(Request.QueryString["searchId"]);
			if (!string.IsNullOrEmpty(searchId))
			{
				strWhere +=" and Id ="+searchId+"";
				urlParams += "&searchId=" + searchId;
			}
			string searchBabyName= dbHelper.FilterSql(Request.QueryString["searchBabyName"]);
			if (!string.IsNullOrEmpty(searchBabyName))
			{
				strWhere +=" and BabyName like '%"+searchBabyName+"%'";
				urlParams += "&searchBabyName=" + searchBabyName;
			}
			string searchBabyBirthday= dbHelper.FilterSql(Request.QueryString["searchBabyBirthday"]);
			if (!string.IsNullOrEmpty(searchBabyBirthday))
			{
				strWhere +=" and BabyBirthday like '%"+searchBabyBirthday+"%'";
				urlParams += "&searchBabyBirthday=" + searchBabyBirthday;
			}
			string searchBabySex= dbHelper.FilterSql(Request.QueryString["searchBabySex"]);
			if (!string.IsNullOrEmpty(searchBabySex))
			{
				strWhere +=" and BabySex ="+searchBabySex+"";
				urlParams += "&searchBabySex=" + searchBabySex;
			}
			string searchWeight= dbHelper.FilterSql(Request.QueryString["searchWeight"]);
			if (!string.IsNullOrEmpty(searchWeight))
			{
				strWhere +=" and Weight ="+searchWeight+"";
				urlParams += "&searchWeight=" + searchWeight;
			}
			string searchHeight= dbHelper.FilterSql(Request.QueryString["searchHeight"]);
			if (!string.IsNullOrEmpty(searchHeight))
			{
				strWhere +=" and Height ="+searchHeight+"";
				urlParams += "&searchHeight=" + searchHeight;
			}
			string searchIntroduction= dbHelper.FilterSql(Request.QueryString["searchIntroduction"]);
			if (!string.IsNullOrEmpty(searchIntroduction))
			{
				strWhere +=" and Introduction like '%"+searchIntroduction+"%'";
				urlParams += "&searchIntroduction=" + searchIntroduction;
			}
			string searchMilkBrand= dbHelper.FilterSql(Request.QueryString["searchMilkBrand"]);
			if (!string.IsNullOrEmpty(searchMilkBrand))
			{
				strWhere +=" and MilkBrand like '%"+searchMilkBrand+"%'";
				urlParams += "&searchMilkBrand=" + searchMilkBrand;
			}
			string searchBabyHeadImg= dbHelper.FilterSql(Request.QueryString["searchBabyHeadImg"]);
			if (!string.IsNullOrEmpty(searchBabyHeadImg))
			{
				strWhere +=" and BabyHeadImg like '%"+searchBabyHeadImg+"%'";
				urlParams += "&searchBabyHeadImg=" + searchBabyHeadImg;
			}
			string searchParentFirstName= dbHelper.FilterSql(Request.QueryString["searchParentFirstName"]);
			if (!string.IsNullOrEmpty(searchParentFirstName))
			{
				strWhere +=" and ParentFirstName like '%"+searchParentFirstName+"%'";
				urlParams += "&searchParentFirstName=" + searchParentFirstName;
			}
			string searchParentLastName= dbHelper.FilterSql(Request.QueryString["searchParentLastName"]);
			if (!string.IsNullOrEmpty(searchParentLastName))
			{
				strWhere +=" and ParentLastName like '%"+searchParentLastName+"%'";
				urlParams += "&searchParentLastName=" + searchParentLastName;
			}
			string searchParentType= dbHelper.FilterSql(Request.QueryString["searchParentType"]);
			if (!string.IsNullOrEmpty(searchParentType))
			{
				strWhere +=" and ParentType ="+searchParentType+"";
				urlParams += "&searchParentType=" + searchParentType;
			}
			string searchLiveProvince= dbHelper.FilterSql(Request.QueryString["searchLiveProvince"]);
			if (!string.IsNullOrEmpty(searchLiveProvince))
			{
				strWhere +=" and LiveProvince like '%"+searchLiveProvince+"%'";
				urlParams += "&searchLiveProvince=" + searchLiveProvince;
			}
			string searchLiveCity= dbHelper.FilterSql(Request.QueryString["searchLiveCity"]);
			if (!string.IsNullOrEmpty(searchLiveCity))
			{
				strWhere +=" and LiveCity like '%"+searchLiveCity+"%'";
				urlParams += "&searchLiveCity=" + searchLiveCity;
			}
			string searchLiveArea= dbHelper.FilterSql(Request.QueryString["searchLiveArea"]);
			if (!string.IsNullOrEmpty(searchLiveArea))
			{
				strWhere +=" and LiveArea like '%"+searchLiveArea+"%'";
				urlParams += "&searchLiveArea=" + searchLiveArea;
			}
			string searchLiveRoad= dbHelper.FilterSql(Request.QueryString["searchLiveRoad"]);
			if (!string.IsNullOrEmpty(searchLiveRoad))
			{
				strWhere +=" and LiveRoad like '%"+searchLiveRoad+"%'";
				urlParams += "&searchLiveRoad=" + searchLiveRoad;
			}
			string searchZipCode= dbHelper.FilterSql(Request.QueryString["searchZipCode"]);
			if (!string.IsNullOrEmpty(searchZipCode))
			{
				strWhere +=" and ZipCode like '%"+searchZipCode+"%'";
				urlParams += "&searchZipCode=" + searchZipCode;
			}
			string searchEMail= dbHelper.FilterSql(Request.QueryString["searchEMail"]);
			if (!string.IsNullOrEmpty(searchEMail))
			{
				strWhere +=" and EMail like '%"+searchEMail+"%'";
				urlParams += "&searchEMail=" + searchEMail;
			}
			string searchBabyTeamName= dbHelper.FilterSql(Request.QueryString["searchBabyTeamName"]);
			if (!string.IsNullOrEmpty(searchBabyTeamName))
			{
				strWhere +=" and BabyTeamName like '%"+searchBabyTeamName+"%'";
				urlParams += "&searchBabyTeamName=" + searchBabyTeamName;
			}
			string searchBabyTeamImg= dbHelper.FilterSql(Request.QueryString["searchBabyTeamImg"]);
			if (!string.IsNullOrEmpty(searchBabyTeamImg))
			{
				strWhere +=" and BabyTeamImg like '%"+searchBabyTeamImg+"%'";
				urlParams += "&searchBabyTeamImg=" + searchBabyTeamImg;
			}
			string searchBabyTeamDeclaration= dbHelper.FilterSql(Request.QueryString["searchBabyTeamDeclaration"]);
			if (!string.IsNullOrEmpty(searchBabyTeamDeclaration))
			{
				strWhere +=" and BabyTeamDeclaration like '%"+searchBabyTeamDeclaration+"%'";
				urlParams += "&searchBabyTeamDeclaration=" + searchBabyTeamDeclaration;
			}
			string searchConfirmTeamId= dbHelper.FilterSql(Request.QueryString["searchConfirmTeamId"]);
			if (!string.IsNullOrEmpty(searchConfirmTeamId))
			{
				strWhere +=" and ConfirmTeamId ="+searchConfirmTeamId+"";
				urlParams += "&searchConfirmTeamId=" + searchConfirmTeamId;
			}
			string searchConfirmTeamName= dbHelper.FilterSql(Request.QueryString["searchConfirmTeamName"]);
			if (!string.IsNullOrEmpty(searchConfirmTeamName))
			{
				strWhere +=" and ConfirmTeamName like '%"+searchConfirmTeamName+"%'";
				urlParams += "&searchConfirmTeamName=" + searchConfirmTeamName;
			}
			string searchStatus= dbHelper.FilterSql(Request.QueryString["searchStatus"]);
			if (!string.IsNullOrEmpty(searchStatus))
			{
				strWhere +=" and Status ="+searchStatus+"";
				urlParams += "&searchStatus=" + searchStatus;
			}
			string searchCreateTime= dbHelper.FilterSql(Request.QueryString["searchCreateTime"]);
			if (!string.IsNullOrEmpty(searchCreateTime))
			{
				strWhere +=" and CreateTime like '%"+searchCreateTime+"%'";
				urlParams += "&searchCreateTime=" + searchCreateTime;
			}
			string searchIp= dbHelper.FilterSql(Request.QueryString["searchIp"]);
			if (!string.IsNullOrEmpty(searchIp))
			{
				strWhere +=" and Ip like '%"+searchIp+"%'";
				urlParams += "&searchIp=" + searchIp;
			}
			
			urlPage = urlPage + urlParams;
			if(!string.IsNullOrEmpty(urlParams))
				urlParams = urlParams.Substring(1, urlParams.Length - 1);
			redirectUrl = redirectUrl + "?" + urlPage;
			
			//数据导出
	 		string toExcel = dbHelper.FilterSql(Request.QueryString["toExcel"]);
            if (toExcel == "1")
            {
                ExcelSubmit(strWhere);
            }
	
			//分页
			Paging(page, strWhere, urlParams);
	
			//业务
			BussessOper(redirectUrl);
	
		
		}
	
	  	#region  --数据导出---
       
        /// <summary>
        /// 保存xls文件
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ExcelSubmit(string sWhere)
        {		 	
			string sSelect = "Id as 'Id',BabyName as '宝宝名字',BabyBirthday as '宝宝生日',BabySex as '宝宝性别',Weight as '宝宝重量',Height as '宝宝身高',Introduction as '宝宝介绍',MilkBrand as '奶粉类型',BabyHeadImg as '宝宝头像',ParentFirstName as '监护人姓',ParentLastName as '监护人名',ParentType as '与监护人关系',LiveProvince as '所在省',LiveCity as '所在市',LiveArea as '所在区',LiveRoad as '所在路',ZipCode as '邮编',EMail as '电子邮箱',BabyTeamName as '宝宝帮名称',BabyTeamImg as '宝宝帮头像',BabyTeamDeclaration as '宝宝帮宣言',ConfirmTeamId as '实际组队Id',ConfirmTeamName as 'ConfirmTeamName',Status as '状态',CreateTime as '创建时间',Ip as 'Ip'";
			
            string some_search = string.Format("select {0} from Baby(nolock) where {1} ", sSelect, sWhere); //查询语句
            DataSet ds = db.returndataset(null, some_search, null, null);

            //填冲到XLS中////
            AdminCommon.xlsGridview(ds, string.Format("数据_{0}", DateTime.Now));
        }

        #endregion
	
	
		#region 分页
		public void Paging(int page, string strWhere, string urlParams)
		{
			dbHelper.pageproret record = new dbHelper.pageproret();
	
			record = db.GetPageRecordSet("Baby", page, 20, "Id", "Id Desc", "*", strWhere);
			int pagecount = record.pagecount;
			DataTable dt = record.recordset;
			List<Baby> datasrc = db.ConvertTo<Baby>(dt).ToList();
				
			 DataList.DataSource = datasrc.Count > 0 ? datasrc : null;
            DataList.DataBind();
		
			string pager = db.BuildPager(page, pagecount, "", urlParams);
			sPage.Text = pager;
		}
	
		#endregion
	
		#region 业务处理
		/// <summary>
		/// 业务处理
		/// </summary>
		/// <param name="redirectUrl"></param>
		public void BussessOper(string redirectUrl)
		{
			if (Request.QueryString["act"] == "del")
			{				
				if (QId != 0)
				{
					DeleteData(QId);
					Response.Redirect(redirectUrl);
				}
			}
	
			if (Request.ServerVariables["REQUEST_METHOD"] == "POST")
			{
				string idStr = dbHelper.FilterSql(Request.Form["SelectID"]);
				if (!string.IsNullOrEmpty(idStr))
				{
					idStr = idStr.Replace(" ", "");
					idStr = idStr.Replace("&nbsp;", "");
					if (!string.IsNullOrEmpty(Request.Form["delete"]))
					{
						DeleteBatchData(idStr);
						Response.Redirect(redirectUrl);
					}
					if (!string.IsNullOrEmpty(Request.Form["pingbi"]))
					{
						SwitchBatchData(0, idStr);
						Response.Redirect(redirectUrl);
					}
					if (!string.IsNullOrEmpty(Request.Form["fabu"]))
					{
						SwitchBatchData(1, idStr);
						Response.Redirect(redirectUrl);
					}
					Response.Redirect(redirectUrl);
					Response.End();
				}
				Baby sdata = new Baby();
				
				//string modid = Request.Form["ModId"] == null ? "0" : Request.Form["ModId"].Trim();
				//int id =sdata.Id = Convert.ToInt32(modid);
					sdata.Id  = Convert.ToInt32(dbHelper.FilterSql(Request.Form["ModId"].Trim())?? "");
					sdata.BabyName  = Convert.ToString(dbHelper.FilterSql(Request.Form["ModBabyName"].Trim())?? "");
					sdata.BabyBirthday  = Convert.ToDateTime((Request.Form["ModBabyBirthday"].Trim())?? "");
					sdata.BabySex  = Convert.ToInt32(dbHelper.FilterSql(Request.Form["ModBabySex"].Trim())?? "");
					sdata.Weight  = Convert.ToInt32(dbHelper.FilterSql(Request.Form["ModWeight"].Trim())?? "");
					sdata.Height  = Convert.ToInt32(dbHelper.FilterSql(Request.Form["ModHeight"].Trim())?? "");
					sdata.Introduction  = Convert.ToString(dbHelper.FilterSql(Request.Form["ModIntroduction"].Trim())?? "");
					sdata.MilkBrand  = Convert.ToString(dbHelper.FilterSql(Request.Form["ModMilkBrand"].Trim())?? "");
					sdata.BabyHeadImg  = Convert.ToString(dbHelper.FilterSql(Request.Form["ModBabyHeadImg"].Trim())?? "");
					sdata.ParentFirstName  = Convert.ToString(dbHelper.FilterSql(Request.Form["ModParentFirstName"].Trim())?? "");
					sdata.ParentLastName  = Convert.ToString(dbHelper.FilterSql(Request.Form["ModParentLastName"].Trim())?? "");
					sdata.ParentType  = Convert.ToInt32(dbHelper.FilterSql(Request.Form["ModParentType"].Trim())?? "");
					sdata.LiveProvince  = Convert.ToString(dbHelper.FilterSql(Request.Form["ModLiveProvince"].Trim())?? "");
					sdata.LiveCity  = Convert.ToString(dbHelper.FilterSql(Request.Form["ModLiveCity"].Trim())?? "");
					sdata.LiveArea  = Convert.ToString(dbHelper.FilterSql(Request.Form["ModLiveArea"].Trim())?? "");
					sdata.LiveRoad  = Convert.ToString(dbHelper.FilterSql(Request.Form["ModLiveRoad"].Trim())?? "");
					sdata.ZipCode  = Convert.ToString(dbHelper.FilterSql(Request.Form["ModZipCode"].Trim())?? "");
					sdata.EMail  = Convert.ToString(dbHelper.FilterSql(Request.Form["ModEMail"].Trim())?? "");
					sdata.BabyTeamName  = Convert.ToString(dbHelper.FilterSql(Request.Form["ModBabyTeamName"].Trim())?? "");
					sdata.BabyTeamImg  = Convert.ToString(dbHelper.FilterSql(Request.Form["ModBabyTeamImg"].Trim())?? "");
					sdata.BabyTeamDeclaration  = Convert.ToString(dbHelper.FilterSql(Request.Form["ModBabyTeamDeclaration"].Trim())?? "");
					sdata.ConfirmTeamId  = Convert.ToInt32(dbHelper.FilterSql(Request.Form["ModConfirmTeamId"].Trim())?? "");
					sdata.ConfirmTeamName  = Convert.ToString(dbHelper.FilterSql(Request.Form["ModConfirmTeamName"].Trim())?? "");
					sdata.Status  = Convert.ToInt32(dbHelper.FilterSql(Request.Form["ModStatus"].Trim())?? "");
					sdata.CreateTime  = Convert.ToDateTime((Request.Form["ModCreateTime"].Trim())?? "");
					sdata.Ip  = Convert.ToString(dbHelper.FilterSql(Request.Form["ModIp"].Trim())?? "");
				var id = sdata.Id;
				if (id == 0)
				{
					//增加
					if (InsertData(sdata))
					{
						Response.Redirect(redirectUrl);
						Response.End();
					}
					else
					{
						Response.Write("error");
						Response.End();
					}
				}
				else
				{
					//修改
					if (UpdateData(sdata))
					{
						Response.Redirect(redirectUrl);
						Response.End();
					}
					else
					{
						Response.Write("error");
						Response.End();
					}
				}
			}
		}
		#endregion
		
		
		#region 增删改
		
		/// <summary>
		/// 添加数据
		/// </summary>
		/// <param name="sdata"></param>
		/// <returns></returns>
		private bool InsertData(Baby sdata)
		{
			string sqlStr = @"INSERT INTO Baby(
					[BabyName],
							[BabyBirthday],
							[BabySex],
							[Weight],
							[Height],
							[Introduction],
							[MilkBrand],
							[BabyHeadImg],
							[ParentFirstName],
							[ParentLastName],
							[ParentType],
							[LiveProvince],
							[LiveCity],
							[LiveArea],
							[LiveRoad],
							[ZipCode],
							[EMail],
							[BabyTeamName],
							[BabyTeamImg],
							[BabyTeamDeclaration],
							[ConfirmTeamId],
							[ConfirmTeamName],
							[Status],
							[CreateTime],
							[Ip]	)VALUES(
					@BabyName,
							@BabyBirthday,
							@BabySex,
							@Weight,
							@Height,
							@Introduction,
							@MilkBrand,
							@BabyHeadImg,
							@ParentFirstName,
							@ParentLastName,
							@ParentType,
							@LiveProvince,
							@LiveCity,
							@LiveArea,
							@LiveRoad,
							@ZipCode,
							@EMail,
							@BabyTeamName,
							@BabyTeamImg,
							@BabyTeamDeclaration,
							@ConfirmTeamId,
							@ConfirmTeamName,
							@Status,
							@CreateTime,
							@Ip)";
			SqlParameter[] parms = new SqlParameter[] {
					new SqlParameter("@BabyName",sdata.BabyName),
							new SqlParameter("@BabyBirthday",sdata.BabyBirthday),
							new SqlParameter("@BabySex",sdata.BabySex),
							new SqlParameter("@Weight",sdata.Weight),
							new SqlParameter("@Height",sdata.Height),
							new SqlParameter("@Introduction",sdata.Introduction),
							new SqlParameter("@MilkBrand",sdata.MilkBrand),
							new SqlParameter("@BabyHeadImg",sdata.BabyHeadImg),
							new SqlParameter("@ParentFirstName",sdata.ParentFirstName),
							new SqlParameter("@ParentLastName",sdata.ParentLastName),
							new SqlParameter("@ParentType",sdata.ParentType),
							new SqlParameter("@LiveProvince",sdata.LiveProvince),
							new SqlParameter("@LiveCity",sdata.LiveCity),
							new SqlParameter("@LiveArea",sdata.LiveArea),
							new SqlParameter("@LiveRoad",sdata.LiveRoad),
							new SqlParameter("@ZipCode",sdata.ZipCode),
							new SqlParameter("@EMail",sdata.EMail),
							new SqlParameter("@BabyTeamName",sdata.BabyTeamName),
							new SqlParameter("@BabyTeamImg",sdata.BabyTeamImg),
							new SqlParameter("@BabyTeamDeclaration",sdata.BabyTeamDeclaration),
							new SqlParameter("@ConfirmTeamId",sdata.ConfirmTeamId),
							new SqlParameter("@ConfirmTeamName",sdata.ConfirmTeamName),
							new SqlParameter("@Status",sdata.Status),
							new SqlParameter("@CreateTime",sdata.CreateTime),
							new SqlParameter("@Ip",sdata.Ip)};
			int ret = db.GetExecuteNonQuery(null, sqlStr, parms);
			return ret > 0;
		}
		
		
		/// <summary>
		/// 修改数据
		/// </summary>		
		/// <param name="sdata"></param>
		/// <returns></returns>
		private bool UpdateData(Baby sdata)
		{
			string sqlStr = @"UPDATE Baby SET
					[BabyName]=@BabyName,
										[BabyBirthday]=@BabyBirthday,
										[BabySex]=@BabySex,
										[Weight]=@Weight,
										[Height]=@Height,
										[Introduction]=@Introduction,
										[MilkBrand]=@MilkBrand,
										[BabyHeadImg]=@BabyHeadImg,
										[ParentFirstName]=@ParentFirstName,
										[ParentLastName]=@ParentLastName,
										[ParentType]=@ParentType,
										[LiveProvince]=@LiveProvince,
										[LiveCity]=@LiveCity,
										[LiveArea]=@LiveArea,
										[LiveRoad]=@LiveRoad,
										[ZipCode]=@ZipCode,
										[EMail]=@EMail,
										[BabyTeamName]=@BabyTeamName,
										[BabyTeamImg]=@BabyTeamImg,
										[BabyTeamDeclaration]=@BabyTeamDeclaration,
										[ConfirmTeamId]=@ConfirmTeamId,
										[ConfirmTeamName]=@ConfirmTeamName,
										[Status]=@Status,
										[CreateTime]=@CreateTime,
										[Ip]=@Ip WHERE Id=@Id";
				
				SqlParameter[] parms = new SqlParameter[] {
					new SqlParameter("@Id",sdata.Id),
										new SqlParameter("@BabyName",sdata.BabyName),
										new SqlParameter("@BabyBirthday",sdata.BabyBirthday),
										new SqlParameter("@BabySex",sdata.BabySex),
										new SqlParameter("@Weight",sdata.Weight),
										new SqlParameter("@Height",sdata.Height),
										new SqlParameter("@Introduction",sdata.Introduction),
										new SqlParameter("@MilkBrand",sdata.MilkBrand),
										new SqlParameter("@BabyHeadImg",sdata.BabyHeadImg),
										new SqlParameter("@ParentFirstName",sdata.ParentFirstName),
										new SqlParameter("@ParentLastName",sdata.ParentLastName),
										new SqlParameter("@ParentType",sdata.ParentType),
										new SqlParameter("@LiveProvince",sdata.LiveProvince),
										new SqlParameter("@LiveCity",sdata.LiveCity),
										new SqlParameter("@LiveArea",sdata.LiveArea),
										new SqlParameter("@LiveRoad",sdata.LiveRoad),
										new SqlParameter("@ZipCode",sdata.ZipCode),
										new SqlParameter("@EMail",sdata.EMail),
										new SqlParameter("@BabyTeamName",sdata.BabyTeamName),
										new SqlParameter("@BabyTeamImg",sdata.BabyTeamImg),
										new SqlParameter("@BabyTeamDeclaration",sdata.BabyTeamDeclaration),
										new SqlParameter("@ConfirmTeamId",sdata.ConfirmTeamId),
										new SqlParameter("@ConfirmTeamName",sdata.ConfirmTeamName),
										new SqlParameter("@Status",sdata.Status),
										new SqlParameter("@CreateTime",sdata.CreateTime),
										new SqlParameter("@Ip",sdata.Ip)};
			int ret = db.GetExecuteNonQuery(null, sqlStr, parms);
			return ret > 0;
		}
		
		
		/// <summary>
		///单个删除
		/// </summary>
		/// <param name="id"></param>
		/// <returns></returns>
		private bool DeleteData(long id)
		{
			string sqlStr = string.Format("DELETE FROM Baby WHERE Id={0}",id);
			
			int ret = db.GetExecuteNonQuery(null, sqlStr, null);
			return ret > 0;
		}
		/// <summary>
		/// 批量删除
		/// </summary>
		/// <param name="idStr"></param>
		/// <returns></returns>
		private bool DeleteBatchData(string idStr)
		{
			string sqlStr = string.Format("DELETE FROM Baby WHERE Id IN ({0})",idStr);
	
			int ret = db.GetExecuteNonQuery(null, sqlStr, null);
			return ret > 0;
		}
		
		
		/// <summary>
		/// 状态操作
		/// </summary>
		/// <param name="optype"></param>
		/// <param name="idStr"></param>
		/// <returns></returns>
		private bool SwitchBatchData(int optype,string idStr)
		{
			string sqlStr = "";
			if(optype==0)
				sqlStr = string.Format("UPDATE Baby SET [Status]=0 WHERE Id IN ({0})",idStr);
			else
				sqlStr = string.Format("UPDATE Baby SET [Status]=1 WHERE Id IN ({0})", idStr);
			
			int ret = db.GetExecuteNonQuery(null, sqlStr, null);
			return ret > 0;
		}
		

		
		#endregion
	}
}


